package cn.wolfcode.shop.controller;

import cn.wolfcode.shop.domain.ShopCar;
import cn.wolfcode.shop.service.IShopCarService;
import cn.wolfcode.shop.vo.JSONResultVo;
import com.alibaba.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;

@RestController
@RequestMapping("/api/shopCars")
public class ShopCarController {
    @Reference
    private IShopCarService shopCarService;

    @PostMapping
    public JSONResultVo addCar(@RequestHeader("user-token") String token, BigDecimal number, Long productSkuId){
        JSONResultVo vo = new JSONResultVo();
        try {
            ShopCar shopCar = shopCarService.addCar(token, number, productSkuId);
            vo.setResult(shopCar);
        } catch (Exception e){
            e.printStackTrace();
            vo.setErrorMsg(e.getMessage());
        }
        return vo;
    }
}
